$(function () {
    $("#selectExtra").val(0);
    timer();
    var time = setInterval('timer()', 3500);

    $(".amount_list_button").click(function () {
        $(".amount_list_button").removeClass("choose_active");
        var aa = $(this).find("span");
        var amount = 0;
        var extra = 0;
        if (aa.length == 2) {
            amount = aa[0].innerText;
            extra = aa[1].innerText;
        }
        $("#selectExtra").val(amount.replace(/[^\d]/g, " "));
        $("#money_give").text(extra);
        $(this).addClass("choose_active");
    })

    /**
     * 充值
     */
    $("#rechargeBtn").click(function () {
        var money = $("#selectExtra").val();
        var money_give = $("#money_give").text();
        var extra = money_give.replace(/[^\d]/g, " ");
        var data = {
            money: money,
            extra: extra
        }
        $.ajax({
            type: "POST",
            url: "../money/recharge",
            dataType: "json",
            contentType: "application/json",
            data: JSON.stringify(data),
            success: function (msg) {
                if (msg.success){
                    toast("Successful recharge");
                    window.location.href = msg.data;
                }else{
                    toast("ERROR recharge");
                }

                // window.location.reload();
            }
        })
    });

    $("#click_to_help").click(function () {
        window.location.href = "help";
    })

    $("#invite").click(function () {
        window.location.href = "invite"
    });


    $("#win").click(function () {
        window.location.href = "win"
    });

    $("#reward").click(function () {
        window.location.href = "reward"
    });

    $("#mime").click(function () {
        window.location.href = "mime"
    });

    $("#recharge").click(function () {
        window.location.href = "mime"
    });

    $("#record_btn").click(function () {
        window.location.href = "record"
    });
})

function timer() {
    $.ajax({
        type: "GET",
        url: "../money/getMoneyLogTopThree",
        dataType: "json",
        contentType: "application/json",
        success: function (msg) {
            var htmls = "";
            for (var i = 0; i < msg.data.length; i++) {
                var d = msg.data[i];
                htmls += "<div data-v-b6601880=\"\"\n" +
                    "                                 style=\"width: 100%; display: flex; flex-direction: row; place-content: center flex-start;" +
                    " align-items: center; height: 32px;\">\n" +
                    "                                <img data-v-b6601880=\"\"\n" +
                    "                                     src=\"../img/zan.png\"\n" +
                    "                                     class=\"win_image\">\n" +
                    "                                <p data-v-b6601880=\"\" class=\"text\" style=\"color: rgb(181, 181, 181);\">";
                htmls += d.loginName + " Recharge <span style=\"color: #FF8800;font-size: 13px\">₹" + d.money + "</span></div>";
            }

            $("#demo1").html(htmls);
        }
    })
}